<?php

namespace app\beautiful\model\member;


use app\common\model\CommonModel;
use think\facade\Db;


class MemberLockModel extends CommonModel{

    protected  $name = 'beautiful_member_lock';

    protected  $pk   = 'member_lock_id';


    public function member(){

        return  $this->hasMany(MemberModel::class,'member_id','member_id');

    }
    public static function list($where,$order=['a.member_lock_id'=>'desc'],$page=1,$limit=10){
        $query = Db::name('beautiful_member_lock')->alias('a')
            ->join('shop b','a.shop_id=b.shop_id')
            ->when(!empty($where['shop_id']),function ($query) use ($where){
                $query->where(['a.shop_id'=>$where['shop_id']]);
            })
            ->when(isset($where['member_id']),function ($query) use ($where){
                $query->where(['a.member_id'=>$where['member_id']]);
            })
            ->field("a.member_id,a.shop_id,b.name as shop_name");
        $count=$query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        return compact('count','list');
    }

}

